<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <meta name="msapplication-tap-highlight" content="no" />
        <title>Hello World</title>
    </head>
    <body> 
    	<a href="javascript:void(0);" id="share_to_friend" class="button block">分享给好友</a>
    	<br/>
    	<a href="javascript:void(0);" id="share_to_timeline" class="button block">分享到朋友圈</a>
     
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript">
           document.addEventListener('deviceready',function(){
        	   //分享给好友
        	   var btn1 = document.getElementById('share_to_friend');
        	   btn1.onclick = function(){
        		   navigator.WechatShare.showToast('请稍后...');
        		   shareToWeixin(false);
        	   }
        	   
        	   //分享到朋友圈
        	   var btn2 = document.getElementById('share_to_timeline');
        	   btn2.onclick = function(){
        		   navigator.WechatShare.showToast('请稍后...');
        		   shareToWeixin(true);
        	   }
        	   
        	   //分享操作的回调 
        	   navigator.WechatShare.sendCallBack = function(result){
        		   switch(result){
            		   case 1:
            		   navigator.WechatShare.showToast('分享成功');
            		   break;
            		   
            		   case 2:
               		   navigator.WechatShare.showToast('取消分享');
               		   break;
                		   
            		   case 3:
               		   navigator.WechatShare.showToast('验证失败');
               		   break;
                		   
            		   case 4:
               		   navigator.WechatShare.showToast('未知错误');
               		   break; 
            	   }
            	   
               }
        	   
           });
           
           
           function shareToWeixin(bool){
        		//这里以分享一个网页为例
  			    var args = {
			            type: 'webpage',
			            url:'http://www.baidu.com',
			            imgUrl:'https://www.baidu.com/img/bdlogo.png',
			            title:'文章标题',
			            desc:'文章简介',
			            isSendToTimeline:bool //true表示分享到朋友圈，false分享给好友
  			    };
   		   	
	   			navigator.WechatShare.send(args);
           } 
           
           
        </script>
    </body>
</html>
